﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Diagnostics;

public partial class helpCenter : System.Web.UI.Page
{
    CommonClass ccObj = new CommonClass();
    DBClass dbObj = new DBClass();
    OrderClass ocObj = new OrderClass();
    protected string menu = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        //获取导航菜单值，用于记录在该页面的子连接中
        menu = Request.QueryString["menu"];
        if (!IsPostBack)
        {
            /*判断是否登录*/
            ST_check_UserLogin();
            //判断是否已点击“搜索”按钮
            ViewState["search"] = null;
            pageBind(); //绑定订单信息
        }
    }
    public void ST_check_UserLogin()
    {
       
             if (Session["Username"] == null)
            {
                 Debug.WriteLine("用户名为空！");
                 Response.Write("<script lanuage=javascript>alert('请登录再查看订单！');location='Default.aspx'</script>");
            //Response.Redirect("Default.aspx");
                 Response.End(); //这里还不知道会起到什么作用  
                 Debug.WriteLine("此处已经执行过跳转！");
            }  
    }



    //绑定货品总额
    public string GetVarGF(string strGoodsFee)
    {
        return ccObj.VarStr(strGoodsFee, 2);
    }
    //绑定运费
    public string GetVarSF(string strShipFee)
    {
        return ccObj.VarStr(strShipFee, 2);
    }
    //绑定总金额
    public string GetVarTP(string strTotalPrice)
    {
        return ccObj.VarStr(strTotalPrice, 2);
    }
    public string GetStatus(int IntOrderID)
    {
        string strSql = "select (case IsConfirm when '0' then '未确认' when '1' then '已确认' end ) as IsConfirm";
        strSql += ",(case IsSend when '0' then '未发货' when '1' then '已发货' end ) as IsSend";
        strSql += ",(case IsEnd when '0' then '未归档' when '1' then '已归档' end ) as IsEnd ";
        strSql += "  from tb_OrderInfo where OrderID=" + IntOrderID;
        DataTable dsTable = dbObj.GetDataSetStr(strSql, "tbOI");
        return (dsTable.Rows[0][0].ToString() + "|" + dsTable.Rows[0][1].ToString() + "<Br>" + dsTable.Rows[0][2].ToString());
    }
    public string GetAdminName(int IntOrderID)
    {
        string strSql = "select AdminName from tb_Admin ";
        strSql += "where AdminID=(select AdminID from tb_OrderInfo";
        strSql += " where OrderID='" + IntOrderID + "')";
        SqlCommand myCmd = dbObj.GetCommandStr(strSql);
        string strAdminName = (dbObj.ExecScalar(myCmd).ToString());
        if (strAdminName == "")
        {
            return "无";
        }
        else
        {
            return strAdminName;
        }
    }
    /// <summary>
    /// 获取指定订单的信息
    /// </summary>
    string strSql;
    public void pageBind()
    {
        strSql = "select * from tb_OrderInfo where ";
        //获取Request["OrderList"]对象的值，确定查询条件
        string strOL = Session["Username"].ToString();
        string TitleInfo = "";
        //switch (strOL)
        //{
        //    case "00"://表示未确定
        //        strSql += "IsConfirm=0";
        //        TitleInfo = "未确认";
        //        break;
        //    case "01"://表示已确定
        //        strSql += "IsConfirm=1";
        //        TitleInfo = "已确认";
        //        break;
        //    case "10": //表示未发货
        //        strSql += "IsSend=0";
        //        TitleInfo = "未发货";
        //        break;
        //    case "11"://表示已发货
        //        strSql += "IsSend=1";
        //        TitleInfo = "已发货";
        //        break;
        //    case "20": //表示收货人未验收货物
        //        strSql += "IsEnd=0";
        //        TitleInfo = "未归档";
        //        break;
        //    case "21": //表示收货人已验收货物
        //        strSql += "IsEnd=1";
        //        TitleInfo = "已归档";
        //        break;
        //    default:
        //        break;
        //}
        strSql += "ReceiverName='"+strOL+"'";
        strSql += " order by OrderDate Desc";
        this.labTitleInfo.Text = TitleInfo;
        //获取查询信息，并将其绑定到GridView控件中
        DataTable dsTable = dbObj.GetDataSetStr(strSql, "tbOI");
        this.gvOrderList.DataSource = dsTable.DefaultView;
        this.gvOrderList.DataKeyNames = new string[] { "OrderID" };
        this.gvOrderList.DataBind();
    }
    /// <summary>
    /// 获取符合条件的订单信息
    /// </summary>
   

    protected void gvOrderList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvOrderList.PageIndex = e.NewPageIndex;
        if (ViewState["search"] == null)
        {
            pageBind();//绑定所有订单信息
        }
        else
        {
            //gvSearchBind();//绑定查询后的订单信息

        }
    }
    
}
